<template>
  <div class="tab-menu">
    <scroll class="scroll-menu" ref="menuScroll">
      <div v-for="(item, index) in categories" :key="index">
        <div class="menu-list-item"
             @click="itemClick(index)"
             :class="{active : index === currentIndex}">
          {{item.title}}
        </div>
      </div>
    </scroll>
  </div>
</template>

<script>
  import Scroll from "components/common/scroll/Scroll";

  export default {
    name: "TabMenu",
    data(){
      return{
        currentIndex: 0
      }
    },
    components:{
      Scroll
    },
    activated() {
      this.$refs.menuScroll.refresh()
    },
    methods:{
      itemClick(index){
        this.currentIndex = index
        this.$emit('selectItem', index)
      }
    },
    props:{
      categories: {
        type: Array,
        default(){return []}
      }
    }
  }
</script>

<style scoped>
  .scroll-menu{
    position: static;
    height: calc(100vh - 49px);
  }
  .active{
    background-color: #fff;
    border-left: 3px solid var(--color-high-text);
  }
  .menu-list-item {
    height: 45px;
    line-height: 45px;
    text-align: center;
    font-size: 14px;
    width: 100px;
  }
  .tab-menu{
    background-color: rgba(100,100,100,0.05);
  }
</style>